package cn.tedu.micro.demo.common.controller;

import cn.tedu.micro.demo.common.protocol.JsonResult;
import cn.tedu.micro.demo.common.service.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order/")
public class StockController {
    @Autowired
    private StockService stockService;

    @PostMapping("/submit")
    public JsonResult<Boolean> submitOrder(
            Integer userId,
            String productCode,
            Integer count
    ){
        Boolean result = stockService.submitOrder(userId, productCode, count);
        if (result){
            return JsonResult.ok("下单成功", result);
        }else {
            return JsonResult.ok("下单失败", result);
        }
    }
}
